package com.esgpro.esg_api.controller;

import com.alibaba.fastjson.JSON;
import com.esgpro.esg_api.pojo.User;
import com.esgpro.esg_api.service.Impl.*;
import com.esgpro.esg_api.util.JSONResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@Api(tags = "首页数据接口列表")
@RequestMapping("/Index")
public class IndexController {
    @Autowired
    UserServiceImpl userService;
    @Autowired
    CompanyServiceImpl companyService;
    @Autowired
    DataContentServiceImpl dataContentService;
    @Autowired
    ESGMessageServiceImpl esgMessageService;
    @Autowired
    IndexServiceImpl service;
    @Autowired
    JSONResult result;

    @RequestMapping("/getPageData")
    public JSON getPageData(int user_id) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("companys", companyService.selectAll().size());
        List<User> users = userService.selectAll();
        int vips = 0;
        for (User user : users) {
            if (user.getLevel() == 2)
                vips += 1;
        }

        map.put("users", users.size());
        map.put("vips", vips);
        map.put("datas", dataContentService.selectAll().size());
        map.put("esgs", esgMessageService.selectAll().size());
        HashMap<String, Object> usermap = new HashMap<>();
        usermap.put("user_id", user_id);
        HashMap<String, Object> select = service.selectByMap(1, 1, usermap);
        Object list = select.get("list");
        map.put("page_data", list);


        return result.getDataResult(map);
    }
}
